# $Id: PKGBUILD 84832 2013-02-25 10:36:39Z spupykin $
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Valeriy Lyasotskiy <onestep@ukr.net>
# Contributor: Jan Willemson <janwil@hot.ee>
# Contributor: Hugo Ideler <hugoideler@dse.nl>
# Contributor: BlackIkeEagle <ike DOT devolder AT gmail DOT com>
# Original PKGBUILD: Andre Naumann <anaumann@SPARCed.org>
# See http://bbs.archlinux.org/viewtopic.php?t=9318&highlight=fpc

pkgname=fpc
pkgver=2.6.2
_gdbver=7.5.1
pkgrel=1
pkgdesc="The Free Pascal Compiler is a Turbo Pascal 7.0 and Delphi compatible 32bit Pascal Compiler. It comes with fully TP 7.0 compatible run-time library."
arch=('i686' 'x86_64')
url="http://www.freepascal.org/"
license=('GPL' 'LGPL' 'custom')
backup=("etc/fpc.cfg")
depends=(ncurses zlib expat)
makedepends=(fpc)
options=(zipman)
source=(ftp://ftp.freepascal.org/pub/fpc/dist/$pkgver/source/fpcbuild-$pkgver.tar.gz
	http://ftp.gnu.org/gnu/gdb/gdb-${_gdbver}.tar.bz2
	fpc-gdb.patch)
md5sums=('89c7e60db6280f3d5cc006a4a9ff43a9'
         '3f48f468b24447cf24820054ff6e85b1'
         '1e45ece6b5d4ee60b860e75926b4122d')

build() {
  cd ${srcdir}/gdb-${_gdbver}
#  ./configure --prefix=/usr --disable-nls --without-python --disable-werror --disable-tui
#  make
#  make -C gdb libgdb.a
#  cp libdecnumber/libdecnumber.a gdb/

  cd ${srcdir}/fpcbuild-$pkgver
#  patch -p1 <$srcdir/fpc-gdb.patch
  export GDBLIBDIR=${srcdir}/gdb-${_gdbver}/gdb
  export LIBGDBFILE=$GDBLIBDIR/libgdb.a
  pushd fpcsrc/compiler
  fpcmake -Tall
  popd
  make build NOGDB=1
}

package() {
  cd ${srcdir}/fpcbuild-$pkgver

  export HOME=$srcdir

  make -j1 PREFIX=${pkgdir}/usr install

  export PATH=$pkgdir/usr/bin:$PATH

  install -Dm0644 fpcsrc/rtl/COPYING.FPC ${pkgdir}/usr/share/licenses/${pkgname}/COPYING.FPC

  [ "$CARCH" = "i686" ] && ln -s /usr/lib/fpc/${pkgver}/ppc386 ${pkgdir}/usr/bin/
  [ "$CARCH" = "x86_64" ] && ln -s /usr/lib/fpc/${pkgver}/ppcx64 ${pkgdir}/usr/bin/

  mkdir -p ${pkgdir}/etc
  ${pkgdir}/usr/lib/fpc/${pkgver}/samplecfg $pkgdir/usr/lib/fpc/${pkgver} ${pkgdir}/etc

  # use -fPIC by default
  echo -e "#ifdef cpux86_64\n# for x86_64 use -fPIC by default\n-Cg\n#endif" >> "$pkgdir/etc/fpc.cfg"

  mv $pkgdir/usr/man $pkgdir/usr/share/

  find $pkgdir/etc/ -type f -exec sed -i "s|$pkgdir||g" {} \;
}
